//
//  Contact.m
//  OC6_字典&数组作业练习
//
//  Created by dllo on 15/10/30.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "Contact.h"

@implementation Contact
@synthesize name = _name;
@synthesize sex = _sex;
@synthesize phonenum = _phonenum;
@synthesize address = _address;
@synthesize group = _group;
@synthesize age = _age;


- (NSString *)name
{
    return [[_name retain] autorelease];
}

- (void)setName:(NSString *)name
{
    if (_name != name) {
        [_name release];
        _name = [name copy];
    }
}

- (NSString *)sex
{
    return [[_sex retain] autorelease];
}

- (void)setSex:(NSString *)sex
{
    if (sex != _sex) {
        [_sex release];
        _sex = [sex copy];
    }
}

- (NSString *)phonenum
{
    return [[_phonenum retain] autorelease];
}

- (void)setPhonenum:(NSString *)phonenum
{
    if (phonenum != _phonenum) {
        [_phonenum release];
        _phonenum = [phonenum copy];
    }
}

- (NSString *)address
{
    return [[_address retain] autorelease];
}

- (void)setAddress:(NSString *)address
{
    if (address != _address) {
        [_address release];
        _address = [address copy];
    }
}

- (NSString *)group
{
    return [[_group retain] autorelease];
}

- (void)setGroup:(NSString *)group
{
    if (group != _group) {
        [_group release];
        _group = [group copy];
    }
}

- (NSInteger)age
{
    return _age;
}

- (void)setAge:(NSInteger)age
{
    _age = age;
}


- (id)initWithName:(NSString *)name sex:(NSString *)sex phonenum:(NSString *)phonenum address:(NSString *)address group:(NSString *)group age:(NSInteger)age
{
    self = [super init];
    if (self) {
        [self setName:name];
        [self setSex:sex];
        [self setPhonenum:phonenum];
        [self setAddress:address];
        [self setGroup:group];
        [self setAge:age];
    }
    return self;
}

- (void)infoAllContact
{
    NSLog(@"%@ %@ %@ %@ %@ %ld", [self name], [self sex], [self phonenum], [self address], [self group], [self age]);
}


- (NSComparisonResult)compareContactByName:(Contact *)contact
{
    return [[self name] compare:[contact name]];
}


- (NSComparisonResult)compareContactByAge:(Contact *)contact
{
    if ([self age] > [contact age]) {
        return NSOrderedAscending;
    }
    if ([self age] < [contact age]) {
        return NSOrderedDescending;
    }
    return NSOrderedSame;
}


- (void)dealloc
{
    [_name release];
    [_sex release];
    [_group release];
    [_address release];
    [_phonenum release];
    [super dealloc];
}


@end
